/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.service;

import java.util.Arrays;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.common.utils.StringUtils;
import com.chlitina.store.modules.expert.dao.ExpertExperienceProblemSolutionDao;
import com.chlitina.store.modules.expert.entity.ExpertExperienceProblemSolution;

/**
 * 专家推荐方案Service
 * @author liujiang
 * @version 2013-07-22
 */
@Component
@Transactional(readOnly = true)
public class ExpertExperienceProblemSolutionService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(ExpertExperienceProblemSolutionService.class);
	
	@Autowired
	private ExpertExperienceProblemSolutionDao expertExperienceProblemSolutionDao;
	
	public ExpertExperienceProblemSolution get(Long id) {
		return expertExperienceProblemSolutionDao.findOne(id);
	}
	
	public List<ExpertExperienceProblemSolution> getByParameters(Long [] parameterIdArray) {
		List<ExpertExperienceProblemSolution> list = expertExperienceProblemSolutionDao.getByParameters(
				Arrays.asList(parameterIdArray));
		return list;
	}
	
	public List<ExpertExperienceProblemSolution> getBySolutionId(Long solution_id) {
		DetachedCriteria dc = expertExperienceProblemSolutionDao.createDetachedCriteria();
		dc.add(Restrictions.eq("solutionFace.id", solution_id));
		return expertExperienceProblemSolutionDao.find(dc);
	}
	
	public Page<ExpertExperienceProblemSolution> find(Page<ExpertExperienceProblemSolution> page, ExpertExperienceProblemSolution expertExperienceProblemSolution) {
		DetachedCriteria dc = expertExperienceProblemSolutionDao.createDetachedCriteria();
		dc.addOrder(Order.desc("id"));
		return expertExperienceProblemSolutionDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(ExpertExperienceProblemSolution expertExperienceProblemSolution) {
		expertExperienceProblemSolutionDao.save(expertExperienceProblemSolution);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		expertExperienceProblemSolutionDao.delete(id);
	}
	
	//获取当前记录排第几位
	public int getIndexById(Long currentId) {
		DetachedCriteria dc = expertExperienceProblemSolutionDao.createDetachedCriteria();
		dc.add(Restrictions.le("id", currentId));
		dc.addOrder(Order.asc("id"));
		return (int)expertExperienceProblemSolutionDao.count(dc);
	}
}
